package com.qf.web.controller;

import com.qf.web.common.qo.MemberRequestParams;
import com.qf.web.common.result.ResponseResult;
import com.qf.web.common.vo.MemberVo;
import com.qf.web.service.MemberService;
import com.qf.web.validator.TypeValidator;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.util.List;

/**
 *
 */
@RestController
@RequestMapping("/member")
@Validated
public class MemberController {
    @Resource
    MemberService memberService;

    @PostMapping("/register")
    public ResponseResult<MemberVo> register(@RequestBody MemberRequestParams memberRequestParams) throws Exception {
        return ResponseResult.success(memberService.register(memberRequestParams));
    }

    @GetMapping("/list")
    public ResponseResult<List<MemberVo>> list(@Min(1) int page, int size) {
        return ResponseResult.success(null);
    }


    @PostMapping("/obj")
    public ResponseResult<List<MemberVo>> testObject(@Valid MemberRequestParams memberRequestParams) {
        return ResponseResult.success(null);
    }

    @PostMapping("/obj1")
    public ResponseResult<List<MemberVo>> testObject1(@RequestBody @Valid MemberRequestParams memberRequestParams) {
        return ResponseResult.success(null);
    }

    @PostMapping("/obj2")
    public ResponseResult<List<MemberVo>> testObject2(@RequestBody @Validated(MemberRequestParams.Update.class) MemberRequestParams memberRequestParams) {
        return ResponseResult.success(null);
    }
        
    /**
     * 1 2 3
     *
     * @param type
     * @return
     */
    @PostMapping("/obj3")
    public ResponseResult<List<MemberVo>> testObject3(@TypeValidator("1,2,3,4") String type) {
        return ResponseResult.success(null);
    }


}
